package com.iotproject.studyservice.controller;

import com.iotproject.commonutils.R;
import com.iotproject.studyservice.entity.UserRememberWord;
import com.iotproject.studyservice.service.StudyWordService;
import com.iotproject.studyservice.service.UserRememberWordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/studyservice/next-word")
public class NextWordController {

    @Autowired
    UserRememberWordService userRememberWordService;

    @Autowired
    StudyWordService studyWordService;

    //选择重新学习
    @GetMapping("reLearnWord/{grade}")
    public R reLearnWord(@PathVariable("grade") String grade, HttpServletRequest httpServletRequest) {
        //清除user_remember_word 表对应数据
//        QueryWrapper<StudyWord> studyWordQueryWrapper = new QueryWrapper<>();
//        studyWordQueryWrapper.eq("grade", grade);
//        List<StudyWord> list = studyWordService.list(studyWordQueryWrapper);
//        List<String> studyWordIdList = new ArrayList<>();
//        for (int i = 0; i < list.size(); i++) {
//            StudyWord studyWord = list.get(i);
//            studyWordIdList.add(studyWord.getId());
//        }
        String memberUserId = studyWordService.getMemberUserId(httpServletRequest);
        QueryWrapper<UserRememberWord> userRememberWordQueryWrapper = new QueryWrapper<>();
        userRememberWordQueryWrapper.eq("user_id", memberUserId);
        userRememberWordQueryWrapper.in("grade", grade);
        boolean remove = userRememberWordService.remove(userRememberWordQueryWrapper);
        return R.ok();
    }

}
